package com.xyyl.patient.service.quickquestion;

import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.common.collect.Lists;
import com.xyyl.patient.core.constant.AppEnum;
import com.xyyl.patient.core.util.StringUtils;
import com.xyyl.patient.entity.question.QuickQuestion;
import com.xyyl.patient.mapper.question.QuickQuestionMapper;
import com.xyyl.patient.service.question.QuickQuestionService;
import com.xyyl.patient.vo.QuestionVo;

/**
 * @ClassName: QuickQuestionImp
 * @Description: 患者提问信息Service
 * @author fangs
 * @date 2017年8月17日
 *
 */
@Service("quickQuestionService")
public class QuickQuestionImp implements QuickQuestionService {

	@Autowired
	private QuickQuestionMapper quickQuestionMapper;

	@Override
	public int insert(QuestionVo map) {
		QuickQuestion quickQuestion = new QuickQuestion();
		if (map != null) {
			
			quickQuestion.setQuestionbody(map.getQuestionbody());
			quickQuestion.setQuestionfiles(map.getQuestionfiles());
			quickQuestion.setArchivesid(map.getArchivesid());
			quickQuestion.setQuestionerid(map.getQuestionerid());
			Timestamp ts = new Timestamp(System.currentTimeMillis());
			String createtime=ts.toString().substring(0, 19);
			quickQuestion.setCreatetime(createtime);
			
			return 	quickQuestionMapper.insert(quickQuestion);
		
		} else {
			return 0;
		}
	}
	@Override
	public int insert(QuickQuestion quickQuestion) {
		Timestamp ts = new Timestamp(System.currentTimeMillis());
		quickQuestion.setCreatetime(ts.toString().substring(0, 19));
		quickQuestion.setQstatus(0);

		return 	quickQuestionMapper.insert(quickQuestion);
	}
	// 分页查询
	@Override
	public List<QuestionVo> queryQuestionList(Integer questionerid) {
        List<QuestionVo> list=Lists.newArrayList(); 
		List<QuickQuestion> quickQuestions = quickQuestionMapper.queryQuestionList(questionerid);
		if (quickQuestions != null && !quickQuestions.isEmpty()) {
			QuestionVo questionVo=null;
			for (QuickQuestion quickQuestion : quickQuestions) {
			 questionVo = new QuestionVo();
				BeanUtils.copyProperties(quickQuestion, questionVo);
				questionVo.setQstatus(AppEnum.QstatusEnum.getName(quickQuestion.getQstatus()));
				list.add(questionVo);
			}
		
		}
		return list;
	}

	@Override
	public QuickQuestion queryQuickQuestionById(Integer questionid) {
		// TODO Auto-generated method stub
		return null;
	}
	
 
	    
	@Override
	public List<Map<String, Object>> queryFinishOrderList(String type1, String type2) {
		
		Integer []q_arr=null;  Integer [] o_arr=null;
		if(StringUtils.isNotEmpty(type1)){
			q_arr=StringUtils.String2IntegerArray(type1);
		}
		if(StringUtils.isNotEmpty(type2)){
			o_arr=StringUtils.String2IntegerArray(type2);
		}
		return quickQuestionMapper.queryFinishOrderList(q_arr, o_arr);
	}

	
}
